Skip to content

Ensure teardown is always executed#117

Open
chitoku-k wants to merge 1 commit into
zunit-zsh:masterfrom
chitoku-k:fix-test-teardown
Open

Ensure teardown is always executed#117
chitoku-k wants to merge 1 commit into
zunit-zsh:masterfrom
chitoku-k:fix-test-teardown

Conversation

@chitoku-k

Copy link
Copy Markdown

In some cases especially when tests failed due to err_exit, the teardown function was not executed. This PR uses trap functions to ensure it is always executed.

@setup {
  tempfile=test
  touch $tempfile
}

@teardown {
  # Here is not executed in some of the following cases
  rm $tempfile
}

@test 'case ok' {
  # This case is totally OK because `run` temporarily disables `err_exit` (using unsetopt)
  run false
}

@test 'case ng' {
  # This PR fixes this case where the test fails with `err_exit` being set
  false
}

I tried to show this by adding test cases that cover them which resulted in the entire test to break because it needs to be somehow failed...

@chitoku-k
chitoku-k requested review from molovo and psprint February 1, 2020 10:05
@molovo
molovo force-pushed the fix-test-teardown branch from 2dcf265 to dd69dba Compare July 14, 2026 23:29
@molovo
molovo removed their request for review July 14, 2026 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant